<template>
	<view style="width: 100vw;height: 100vh;">
		<view style="display: flex;flex-direction: row;flex-wrap: wrap;width:100vw;background-color: #fff;">
			<view v-for="(product, index2) in item" :key='product.id' v-if="product.blockName=='chooseprodcut_image1_corner2' || product.blockName=='chooseprodcut_line1_nosplit'">
				<view style="display: flex;flex-direction: row;flex-wrap: wrap;" v-if="product.blockName=='chooseprodcut_image1_corner2'" >
					<view style="position: relative;width: 80px;height: 100%;">
						<image @click="navitogood(item,index)"  :src="pic_address + product.data[0].style.colValue" @error="picerror(index)" style="width: 80px;height: 80px;padding:8px 3px;top: 0;left: 0;"></image> 
					</view>
				</view>
				<view style="width:calc(100vw - 100px) ;height: 100%;padding-left: 8px;padding-top: 10px;" v-if="product.blockName=='chooseprodcut_line1_nosplit'">
					<view v-for="(gdetail) in product.data" :key='gdetail.name'>
						<view style="color: #666;font-size: 14px; display: flex;flex-direction: row;align-items: center;">
							<view style="min-width: 16vw;">{{gdetail.style.colText}}:</view>
							<view style="border-radius: 5px;padding: 0 5px;">{{gdetail.style.colValue==null?'':gdetail.style.colValue}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view style="padding:0 10px;">
			<view>{{datahead[0][specName1]}}</view>
			<checkbox-group @change="changecheck('head',$event)">
				<view style="display: flex;flex-direction: row;flex-wrap: wrap;align-items: center;text-align: center;">
					<view v-for="(item) in datahead" :key="index">
						<view style="margin-right: 8px;"><checkbox  :checked="item.checked" :value="item[specValue1]" style="transform:scale(0.8);">{{item[specValue1]}}</checkbox> </view>
					</view>
				</view>
			</checkbox-group>
			<view>{{datahead2[0][specName2]}}</view>
			<checkbox-group @change="changecheck('head2',$event)">
				<view style="display: flex;flex-direction: row;flex-wrap: wrap;align-items: center;text-align: center;">
					<view v-for="(item) in datahead2" :key="index">
						<view style="margin-right: 8px;"><checkbox :checked="item.checked" :value="item[specValue2]" style="transform:scale(0.8);">{{item[specValue2]}}</checkbox> </view>
					</view>
				</view>
			</checkbox-group>
		</view>
		<view style="padding:0 10px;margin-top:20px;">
			<view style="display: flex;flex-direction: row;justify-content:space-between;">
				<view>规格</view>、
				<view>数量</view>
			</view>
			<view style="display: flex;flex-direction: column;">
				<view v-for="(item,index) in datadetail" :key="index" v-if="item.visible">
					<view style="display: flex;flex-direction: row;justify-content:space-between;padding-top:10px;">
						<view>{{item[specValue1]}}/{{item[specValue2]}}</view>
						<view @click="navitogood(item,index)">
							<view v-if="item[ColNameQty]==0" class="iconfont icon-jiahao" style="text-align: center;align-items: center;font-size: 20px;min-width: 50px;"></view>
							<view v-else style="color: #F55C23;text-align: center;display: flex;flex-direction: row;text-align: center;min-width: 50px;justify-content:center;">
								<view class="iconfont icon-bianji" style="margin-left: 5px;align-items: center;">{{item[ColNameQty]}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<view style="width: 100vw;height: 44px;display: flex;position: absolute;bottom: 0;z-index: 1000;">
			<view style="width: 75vw;background-color: #333;display: flex;z-index: 1000;">
				<view style="position: relative;"><text class="iconfont icon-icozhuanhuan" style="font-size: 28px;color: #333;background-color: #f7d08d;border-radius: 50%;padding: 10px;margin: -10px 10px 0 10px;"></text>
					<view v-if="dataitem[ColNameQty]!=undefined &&dataitem[ColNameQty]>0" style="position: absolute;top: -5px; right: 5px;color: #fff; background-color: #e85a71;border-radius: 16px;padding: 0 5px;font-size: 12px;">
						{{dataitem[ColNameQty]}}
					</view>
				</view>
			</view>
			<view @click="naviback" style="width: 25vw;background-color: #e85a71;align-items: center;display: flex; justify-content: center;z-index: 800;">选好了</view>
		</view>
		
		<view v-if="iscontentdetail1"  @click="closemask" style="backface-visibility: hidden;top: 0;right: 0;left: 0;bottom: 0;position: fixed;overflow: hidden;width: 100vw;height: 100%;opacity: 1;background-color: rgba(0,0,0,0.4);z-index: 9000;">
			<view @click.stop="" :style="{'height':maskheight+'px'}" style="opacity: 1;background-color: #fff;z-index: 9000;bottom: 0px;position: absolute;width: 100vw;">
				<stylesku ref="stylesku" :pagename='pageName' :datalist='halfdatalist[0]' :pic_address='pic_address' :jsonoptions='jsonoptions' :divArea='halfDivArea' :parenttype='parenttype'></stylesku>
			</view>
		</view>
	</view>
</template>

<script>
	var util = require("../../utils/util.js");
	var infolistutil = require("../../utils/infolistutil.js");
	import stylesku from "../../components/stylesku/stylesku"
	export default {
		components:{
			stylesku
		},
		data() {
			return {
				selecteditem:0,
				selectedtitle:'',
				goodindex:0,
				skuindex:0,
				skuitemindex:0,
				cartcount:0,
				skugood:[],
				goodsarr:[],
				ismask:false,
				skugoodnum:[],
				cartmask:false,
				cartarr:[],
				giftarr:[],
				summoney:0,
				code:'',
				pageName:'',
				templetName:'',
				divArea:'',
				modid:'',
				menuid:'',
				div:[],
				halfdatalist:[],
				divhead:{},
				divhead2:{},
				divdetail:{},
				datahead:[],
				datahead2:[],
				datadetail:[],
				pic_address:'',
				expArgs:{},
				item:[],
				dataitem:{},
				specName1:'',
				specName2:'',
				specValue1:'',
				specValue2:'',
				iscontentdetail1:false,
				ColNameQty:'',
				colNameWriteBackBasedOn:'',
				maskheight:370,
				parenttype:'multi',
				skuselected:[],
				productindex:0
			}
		},
		onLoad:function(options){
			var that = this
			this.pic_address = getApp().globalData.pic_address
			var item = JSON.parse(options.item)
			that.item = item
			that.dataitem = JSON.parse(options.dataitem)
			that.skuselected = JSON.parse(options.skuitems)
			console.log(that.dataitem)
			var productCode = uni.getStorageSync('productCode')
			var sessionId = uni.getStorageSync('sessionId')
			var projectCode = uni.getStorageSync('projectCode')
			var terminaltype = uni.getStorageSync('terminaltype')
			var dbId = uni.getStorageSync('dbId')
			var userId = uni.getStorageSync('userId')
			var userName = uni.getStorageSync('userName')
			var pageName = options.pagename
			var templetName = options.templatename
			var menuid = options.menuid
			var modid = options.modid
			var title = options.title==undefined?'':options.title
			if(title!='')  uni.setNavigationBarTitle({title:title})
			var expArgs = {}
			try{
				expArgs = JSON.parse(options.expArgs)
			}catch(e){}
			
			console.log(expArgs)
			that.modid = modid
			that.menuid = menuid
			that.pageName = pageName
			that.templetName = templetName
			that.expArgs = expArgs
			that.ColNameQty = options.ColNameQty
			that.colNameWriteBackBasedOn = options.colNameWriteBackBasedOn
			console.log(options.ColNameQty)
			var injson = '{"productCode":"' + productCode + '","terminalType":"' + terminaltype + '","projectCode":"' +
				projectCode + '","dbId":"' + dbId + '","templetName":"' + templetName + '","pageName":"' + pageName +
				'","menuId":"'+menuid+'","modId":"' + modid + '","sessionId":"' + sessionId + '","userId":"' + userId +
				'","userName":"' + userName + '"}';
			console.log(injson)
			
			uni.showLoading({ title: '加载中' })
			uni.request({
				url: getApp().globalData.app_address + '?method=saas_PageStyle&parse=json',
				data: injson,
				method: 'POST',
				header: {
					'content-type': 'application/x-www-form-urlencoded'
				},
				success: function(res) {
					var result = res.data;
					console.log(JSON.parse(JSON.stringify(result)))
					uni.hideLoading()
					var div = result.data.div
					that.div = div
					div.forEach((val, index)=>{
						var datastyle = val.style.colStyle
						var divBlocks = val.divClass.divBlocks
						var divArea = val.divArea
						if(divArea === 'dw_mx_head'){
							that.divhead = val
							that.specValue1 = val.style.specValue
							that.specName1 = val.style.specName
						}else if(divArea === 'dw_mx_head2'){
							that.divhead2 = val
							that.specName2 = val.style.specName
							that.specValue2 = val.style.specValue
						}else if(divArea === 'dw_mx_detail'){
							that.divdetail = val
							options['divArea'] = divArea
							that.jsonoptions = options
						}
						var DataObjectExtData = uni.getStorageSync('DataObjectExtData')
						var customlist = []
						
						var temconditions = {}
						var conditions = val.style.conditions
						console.log(conditions)
						if(val.style.conditions != undefined){
							if(JSON.stringify(expArgs) != '[]' && JSON.stringify(conditions) != '[]' && JSON.stringify(conditions) != undefined){
								var temobj = {}
								for(var m=0; m<conditions.length; m++){
									for(var n=0; n<expArgs.length; n++){
										if(conditions[m].divArea == expArgs[n].divArea){
											var foreignKeyArr = conditions[m].foreignKeyArr
											for(var o=0; o<foreignKeyArr.length; o++){
												if(expArgs[n].colName == foreignKeyArr[o].baseKey){
													temobj[foreignKeyArr[o].foreignKey] = expArgs[n].value
												}
												if(foreignKeyArr[o].type === 'value'){
													temobj[foreignKeyArr[o].foreignKey] = foreignKeyArr[o].value 
												}
											}
										}
									}
								}
								temconditions[divArea] = temobj
								if(JSON.stringify(temobj) != '{}'){
									for(var kk=0;kk<datastyle.length;kk++){
										for(var mm=0; mm<expArgs.length; mm++){
											if(datastyle[kk].name == expArgs[mm].colName){
												datastyle[kk].style['colValue'] = expArgs[mm].value
												datastyle[kk].style.ismodified = true
												datastyle[kk].style['value'] = expArgs[mm].value
											}
										}
									}
								}
							}
						}
						
					
						var dataObject = val.style.dataObject
						that.dataObject = dataObject
						var pageConditions = {}
						pageConditions['pageNumber'] = 1
						pageConditions['rowsPerPage'] = 20
						pageConditions['isAllData'] = false
						that.pageConditions = pageConditions
						
						var replaceConditions = {}
						var replaceColumns = val.style.replaceColumns
						if(JSON.stringify(replaceColumns) != '[]' && replaceColumns != undefined){
							for(var q=0; q<replaceColumns.length; q++){
								var type = replaceColumns[q].type
								if(type == 'column'){
									var colName= replaceColumns[q].column.colName
									replaceConditions[replaceColumns[q].toReplace] = conditions[colName]
								}
							}
						}
						var injson2 = '{"productCode":"' + productCode + '","terminalType":"' + terminaltype + '","projectCode":"' +
							projectCode + '","dbId":"' + dbId + '","templetName":"' + templetName + '","pageName":"' + pageName +
							'","menuId":"'+menuid+'","modId":"' + modid + '","sessionId":"' + sessionId + '","userId":"' + userId +
							'","userName":"' + userName + '","divArea":"' + divArea + '","dataObject":"' + dataObject + 
							'","conditions":' + JSON.stringify(temconditions) + 
							',"replaceConditions":' + JSON.stringify(replaceConditions) + 
							',"pageConditions":' + JSON.stringify(that.pageConditions) + '}';
						console.log('injson2' + injson2)
						
						var url = getApp().globalData.app_address + '?method=saas_PageDivData&parse=json'
						var blockstyle = []
						that.$options.methods.getdatalist(url, injson2, blockstyle, divArea, val.type, that)
					})
				}
			})
			
			uni.$on("updatelist", (listtype, listindex,listblockindex, listitemindex, itemobj,pagename)=>{
				if(pagename!=this.pageName)return
				var item = that.halfdatalist[0][listblockindex].data[listitemindex]
				item.style = itemobj
				if(itemobj.itemchanged !=undefined && itemobj.itemchanged!= ''){
					var content = itemobj.itemcontent
					var itemchanged = itemobj.itemchanged
					var dddwcolumn = ''
					var itemcolumn = ''
					if(itemchanged!=undefined || itemchanged!= ''){
						dddwcolumn = itemchanged.split('.')[1]
						itemcolumn = itemchanged.split('@')[0]
					}
					for(var i=0;i<content.length;i++){
						if(dddwcolumn != '' && dddwcolumn == content[i].name){
							var dataList = that.halfdatalist[0]
							dataList.forEach((val) => {
								val.data.forEach((val2, index2, origin) => {
									if(val2.name == itemcolumn){
										if(index2 == 0){console.log(origin)}
										origin[index2].style.value = content[i].style.value
										origin[index2].style.colValue = content[i].style.value
										origin[index2].style.coldisplay = content[i].style.value
										origin[index2].style.ismodified = true
									}
								})
							})
							that.halfdatalist[0] = dataList
						}
					}
				}
				
				that.halfdatalist[0][listblockindex].data[listitemindex] = item
				
				var itemexpstr = util.gettagvalue(itemobj.tag,'computelist')
				if(itemexpstr!=''){
					itemexpstr = itemexpstr.replace(/'/g, '"').toString()
					var itemexp = JSON.parse(itemexpstr)
					var halfdatalist = that.halfdatalist[0]
					var skuitemdata = {}
					halfdatalist.forEach((val)=>{
						val.data.forEach((val2)=>{
							skuitemdata[val2.name] = val2.style.colValue
						})
					})
					itemexp.forEach((val)=>{
						halfdatalist.forEach((val2,index2)=>{
							val2.data.forEach((val3,index3)=>{
								if(val3.name == val){
									var ss = val3.style.expression
									var search = '#'
									var positions = []
									var index = ss.indexOf(search)
									var num = 0
									while(index !== -1){
										positions.push(index)
										index = ss.indexOf(search, index+1)
									}
									console.log(positions)
									var ps = []
									for (var i = 0; i < positions.length; i++) {
										if(i%2 == 0){
											var c = ss.substring(positions[i]+1, positions[i+1])
											ps.push(['#'+c+'#', skuitemdata[c]])
										}
									}
									ps.forEach((valps)=>{
										ss= ss.replace(valps[0], valps[1])
									})
									var productCode = uni.getStorageSync('productCode')
									var sessionId = uni.getStorageSync('sessionId')
									var projectCode = uni.getStorageSync('projectCode')
									var terminaltype = uni.getStorageSync('terminaltype')
									var dbId = uni.getStorageSync('dbId')
									var userId = uni.getStorageSync('userId')
									var userName = uni.getStorageSync('userName')
									var injson2 = '{"productCode":"' + productCode + '","terminalType":"' + terminaltype + '","projectCode":"' +
										projectCode + '","dbId":"' + dbId + '","templetName":"' + that.templetName + '","pageName":"' + that.pageName +
										'","menuId":"'+that.menuid+'","modId":"' + that.modid + '","sessionId":"' + sessionId + '","userId":"' + userId +
										'","userName":"' + userName + '","divArea":"' + that.jsonoptions.divArea + '","dataObject":"' + that.jsonoptions.dataObject + 
										'","colNameInput":"' + item.name + 
										'","colNameExp":"' + val + 
										'","expression":"' + ss + '"}';
									console.log(injson2)
									uni.request({
										url: getApp().globalData.app_address + '?method=saas_PageDivExpression&parse=json',
										data: injson2,
										method: 'POST',
										header: {'content-type': 'application/x-www-form-urlencoded'},
										success: function(res) {
											var result = res.data;
											var calcres = result.data
											val3.style.colValue = calcres
											val3.style.value = calcres
											val3.style.coldisplay = calcres
											val3.style.ismodified = true
											that.halfdatalist[0][index2].data[index3] = val3
											that.$forceUpdate()
										},
									})
								}
							})
						})
					})
				}
					
			})
			
			uni.$on("cancelsku", ()=>{
				this.iscontentdetail1 = false
			})
			
			uni.$on("ensuresku", (datalist,parenttype,pagename)=>{
				if(pagename!=this.pageName)return
				console.log(pagename)
				var skuitem = {}
				datalist.forEach((val)=>{
					val.data.forEach((val2)=>{
						skuitem[val2.name] = val2.style.colValue
					})
				})
				var item = that.item
				item.forEach((val2)=>{
					val2.data.forEach((val3)=>{
						if(val3.name == 'dldm'){
							skuitem['dm'] = val3.style.colValue
						}
					})
				})
				var ColNameQty = that.ColNameQty
				var colNameWriteBackBasedOn = that.colNameWriteBackBasedOn
				var dataitem = that.datadetail[that.productindex]
				dataitem[ColNameQty] = skuitem[ColNameQty]
				that.datadetail[that.productindex] = dataitem
				console.log(skuitem)
				var itemindex = undefined
				var skuselected = that.skuselected
				if(JSON.stringify(skuselected)!= '[]'){
					skuselected.forEach((val,index)=>{
						if(val[colNameWriteBackBasedOn] == skuitem[colNameWriteBackBasedOn]){
							itemindex = index
						}
					})
				}
				if(itemindex != undefined){
					if(skuitem[ColNameQty]>0){
						skuselected.splice(itemindex,1,skuitem)
					}else{
						skuselected.splice(itemindex, 1)
					}
				}else{
					skuselected.push(skuitem)
				}
				that.skuselected = skuselected
				var sl = 0
				skuselected.forEach((val2)=>{
					sl += parseInt(val2[ColNameQty])
				})
				that.dataitem[ColNameQty] = sl
				
				this.iscontentdetail1 = false
			})
		},
		
		methods:{
			async getdatalist(url, injson2,blockstyle,divarea,valtype,that){
				console.log(divarea)
				const { data: res } = await infolistutil.post2(url, injson2);
				var result = res.data;
				console.log(res)
				var datalisttemp = res.data.div.value
				if(divarea == 'dw_mx_head'){
					datalisttemp.forEach((val)=>{
						val['checked'] = true
					})
					that.datahead = datalisttemp
				}else if(divarea == 'dw_mx_head2'){
					datalisttemp.forEach((val)=>{
						val['checked'] = true
					})
					that.datahead2 =  datalisttemp
					console.log(that.datahead2)
				}else if(divarea == 'dw_mx_detail'){
					var skuselected = that.skuselected
					var ColNameQty = that.ColNameQty
					var colNameWriteBackBasedOn = that.colNameWriteBackBasedOn
					datalisttemp.forEach((val)=>{
						val['visible'] = true
						if(JSON.stringify(skuselected)!='[]'){
							skuselected.forEach((val2)=>{
								if(val2[colNameWriteBackBasedOn] == val[colNameWriteBackBasedOn]){
									val[ColNameQty] = val2[ColNameQty]
								}
							})
						}
					})
					that.datadetail = datalisttemp
					var sl = 0
					skuselected.forEach((val2)=>{
						sl += parseInt(val2[ColNameQty])
					})
					that.dataitem[ColNameQty] = sl
					that.$forceUpdate()
				}
			
			},
				
			navitogood(item,index){
				var that = this
				var divlist = that.divdetail
				that.productindex =  index
				var rowClick = divlist.style.rowClick
				console.log(rowClick)
				var datalist = item
				try{
					var toDo = rowClick.toDo
					var pagename = rowClick.pageName
					var templetname = rowClick.templetName
					var expArgs = rowClick.expArgs
					var title = rowClick.title
					expArgs.forEach((val4)=>{
						val4['value'] = datalist[val4.colName]
					})
					
					if(toDo=='openhalfpage'){
						that.$options.methods.getHalfPage(templetname, pagename,expArgs,that)
						throw 'ENDFOREACH'
					}
				}catch(e){
					console.log(e)
				}
			},
			
			getHalfPage(templetName, pageName,expArgs,that){
				console.log(expArgs)
				var productCode = uni.getStorageSync('productCode')
				var sessionId = uni.getStorageSync('sessionId')
				var projectCode = uni.getStorageSync('projectCode')
				var terminaltype = uni.getStorageSync('terminaltype')
				var dbId = uni.getStorageSync('dbId')
				var userId = uni.getStorageSync('userId')
				var userName = uni.getStorageSync('userName')
				var injson = '{"productCode":"' + productCode + '","terminalType":"' + terminaltype + '","projectCode":"' +
					projectCode + '","dbId":"' + dbId + '","templetName":"' + templetName + '","pageName":"' + pageName +
					'","menuId":"'+that.menuid+'","modId":"' + that.modid + '","sessionId":"' + sessionId + '","userId":"' + userId +
					'","userName":"' + userName + '"}';
				console.log(injson)
				
				uni.showLoading({ title: '加载中' })
				uni.request({
					url: getApp().globalData.app_address + '?method=saas_PageStyle&parse=json',
					data: injson,
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: function(res) {
						var result = res.data;
						console.log(JSON.parse(JSON.stringify(result)))
						uni.hideLoading()
						var div = result.data.div[0]
						that.halfdiv = div
						var datastyle = div.style.colStyle
						var divBlocks = div.divClass.divBlocks
						var divArea = div.divArea
						that.ColNameQty = div.style.ColNameQty
						that.colNameWriteBackBasedOn = div.style.colNameWriteBackBasedOn
						
						
						if(JSON.stringify(datastyle)!='[]'){
							var listindex = 0
							for(var i=0;i<datastyle.length;i++){
								if(datastyle[i].style.editStyle=='dddw' && datastyle[i].style.dddw.name!='d_nvo_uipage_dwc'&&datastyle[i].style.colVisible){
									datastyle[i].style['typeindex'] = listindex
									listindex++
									var multiselect = util.gettagvalue(datastyle[i].style.tag, 'multiselect')
									if(multiselect == 1){
										that.repeatByColName = datastyle[i].name
										that.repeatByColTag = datastyle[i].style.tag
									}
								}
							}
						}
						
						var DataObjectExtData = uni.getStorageSync('DataObjectExtData')
						var customlist = []
						var temconditions = {}
						var conditions = div.style.conditions
						if(div.style.conditions != undefined){
							if(JSON.stringify(expArgs) != '[]' && JSON.stringify(conditions) != '[]' && JSON.stringify(conditions) != undefined){
								var temobj = {}
								for(var m=0; m<conditions.length; m++){
									for(var n=0; n<expArgs.length; n++){
										if(conditions[m].divArea == expArgs[n].divArea){
											var foreignKeyArr = conditions[m].foreignKeyArr
											for(var o=0; o<foreignKeyArr.length; o++){
												if(expArgs[n].colName == foreignKeyArr[o].baseKey){
													temobj[foreignKeyArr[o].foreignKey] = expArgs[n].value
												}
												if(foreignKeyArr[o].type === 'value'){
													temobj[foreignKeyArr[o].foreignKey] = foreignKeyArr[o].value 
												}
											}
										}
									}
								}
								temconditions[divArea] = temobj
							}
						}
						
						for(var k=0;k<datastyle.length;k++){
							if(datastyle[k].style.editStyle=='editmask' && datastyle[k].style.colType=='datetime'){
								datastyle[k].style['starts'] = '1990-01-01'
								datastyle[k].style['ends'] = '2100-01-01'
								datastyle[k].style['placeholder'] = '请选择'
								if(that.opttype == 'billadd'){
									var date = new Date()
									var time = util.formatTime2(date)
									datastyle[k].style['value'] = time
									datastyle[k].style['coldisplay'] =time
									datastyle[k].style['colValue'] = time
								}
							}
						}
						
						var divblock = {}
						var blockstyle = []
						if(JSON.stringify(divBlocks) != '[]' && divBlocks != undefined ){
							divBlocks.forEach((val, index) => {
								var block = []
								if(val.colNames != undefined){
									val.colNames.forEach((val2, index2) => {
										datastyle.forEach((val3, index3) => {
											if(val2 == val3.name){
												var item = datastyle[index3]
												datastyle.splice(index3, 1)
												block.push(item)
											}
										})
									})
								}
								divblock['blockName'] = val.blockName
								divblock['style'] = block
								divblock['property'] = val.property
								blockstyle.push(JSON.parse(JSON.stringify(divblock)) )
							})
						}
						if(JSON.stringify(datastyle) != '[]'){
							divblock['blockName'] = ''
							divblock['style'] = datastyle
							divblock['property'] = ''
							blockstyle.push(JSON.parse(JSON.stringify(divblock)))
						}
						
						var dataObject = div.style.dataObject
						var pageConditions = {}
						pageConditions['pageNumber'] = 1
						pageConditions['rowsPerPage'] = 20
						pageConditions['isAllData'] = false
						that.pageConditions = pageConditions
						
						var replaceConditions = {}
						var replaceColumns = div.style.replaceColumns
						if(JSON.stringify(replaceColumns) != '[]' && replaceColumns != undefined){
							for(var q=0; q<replaceColumns.length; q++){
								var type = replaceColumns[q].type
								if(type == 'column'){
									var colName= replaceColumns[q].column.colName
									replaceConditions[replaceColumns[q].toReplace] = conditions[colName]
								}
								if(type == 'value'){
									var replaceValue = replaceColumns[q].value
									if(replaceValue == "#PROJECTCODE#"){
										replaceConditions[replaceColumns[q].toReplace] = uni.getStorageSync('projectCode')
									}
								}
							}
						}
						
						console.log(blockstyle)
						that.halfDivArea = divArea
						that.halfconditions = temconditions
						var injson2 = '{"productCode":"' + productCode + '","terminalType":"' + terminaltype + '","projectCode":"' +
							projectCode + '","dbId":"' + dbId + '","templetName":"' + templetName + '","pageName":"' + pageName +
							'","menuId":"'+that.menuid+'","modId":"' + that.modid + '","sessionId":"' + sessionId + '","userId":"' + userId +
							'","userName":"' + userName + '","divArea":"' + divArea + '","dataObject":"' + dataObject + 
							'","conditions":' + JSON.stringify(temconditions) + 
							',"replaceConditions":' + JSON.stringify(replaceConditions) + 
							',"pageConditions":' + JSON.stringify(that.pageConditions) + '}';
						console.log('injson2' + injson2)
						var colNameWriteBackBasedOnvalue = that.datadetail[that.productindex][that.colNameWriteBackBasedOn]
						var skuselected = that.skuselected
						skuselected.forEach((skus)=>{
							if(skus[that.colNameWriteBackBasedOn] == colNameWriteBackBasedOnvalue){
								var datalist = []
								var datalisttemp = []
								datalisttemp.push(skus)
								datalisttemp.forEach((val,index) => {
									var listtemp = []
									blockstyle.forEach((val2, index2) => {
										var style = val2.style
										var obj = {}
										obj['opttype'] = 'update'
										obj['divArea'] = divArea
										style.forEach((val3, index3,origin) => {
											if(val3.style.editStyle === 'dddw' && val3.style.dddw.name=='d_nvo_uipage_dwc'){
												var tag_dddwName = val3.style.tag_dddwName
												var tabval =  val[val3.name]
												var customlist = []
												for(var i=0; i<DataObjectExtData.length;i++){
													if(DataObjectExtData[i].dataobjectname == tag_dddwName && DataObjectExtData[i].coldata ==tabval){
														origin[index3].style['value'] = DataObjectExtData[i].coldata
														origin[index3].style['coldisplay'] = DataObjectExtData[i].coldisplay
														origin[index3].style['colValue'] = DataObjectExtData[i].coldisplay
													}
													if(DataObjectExtData[i].dataobjectname == tag_dddwName){
														customlist.push(DataObjectExtData[i])
														origin[index3].style['codeTable'] = customlist
													}
												}
											}else if(val3.name == 'urlfilename' || val3.name == 'urlfilenamex'){
												origin[index3].style['value'] = getApp().globalData.pic_address + val[val3.name]
												origin[index3].style['coldisplay'] = getApp().globalData.pic_address + val[val3.name]
												origin[index3].style['colValue'] = val[val3.name]
											}else{
												origin[index3].style['value'] = val[val3.name]
												origin[index3].style['coldisplay'] = val[val3.name]
												origin[index3].style['colValue'] = val[val3.name]
											}
										})
										obj['property'] = val2.property
										obj['blockName'] = val2.blockName
										obj['id'] = index2
										obj['blockid'] = index
										obj['data'] = JSON.parse(JSON.stringify(style))
										listtemp.push(JSON.parse(JSON.stringify(obj)))
									})
									datalist.push(listtemp)
								})
								that.halfdatalist = datalist
								that.iscontentdetail1 = true
							}
						})
						
						if(that.iscontentdetail1)return
						
						uni.request({
							url: getApp().globalData.app_address + '?method=saas_PageDivData&parse=json',
							data: injson2,
							method: 'POST',
							header: {
								'content-type': 'application/x-www-form-urlencoded'
							},
							success: function(res2) {
								var result = res2.data;
								console.log(res2)
								var datalisttemp = result.data.div.value
								var datalist = []
								datalisttemp.forEach((val,index) => {
									var listtemp = []
									blockstyle.forEach((val2, index2) => {
										var style = val2.style
										var obj = {}
										obj['opttype'] = 'update'
										obj['divArea'] = divArea
										style.forEach((val3, index3,origin) => {
											if(val3.style.editStyle === 'dddw' && val3.style.dddw.name=='d_nvo_uipage_dwc'){
												var tag_dddwName = val3.style.tag_dddwName
												var tabval =  val[val3.name]
												var customlist = []
												for(var i=0; i<DataObjectExtData.length;i++){
													if(DataObjectExtData[i].dataobjectname == tag_dddwName && DataObjectExtData[i].coldata ==tabval){
														origin[index3].style['value'] = DataObjectExtData[i].coldata
														origin[index3].style['coldisplay'] = DataObjectExtData[i].coldisplay
														origin[index3].style['colValue'] = DataObjectExtData[i].coldisplay
													}
													if(DataObjectExtData[i].dataobjectname == tag_dddwName){
														customlist.push(DataObjectExtData[i])
														origin[index3].style['codeTable'] = customlist
													}
												}
											}else if(val3.name == 'urlfilename' || val3.name == 'urlfilenamex'){
												origin[index3].style['value'] = getApp().globalData.pic_address + val[val3.name]
												origin[index3].style['coldisplay'] = getApp().globalData.pic_address + val[val3.name]
												origin[index3].style['colValue'] = val[val3.name]
											}else{
												origin[index3].style['value'] = val[val3.name]
												origin[index3].style['coldisplay'] = val[val3.name]
												origin[index3].style['colValue'] = val[val3.name]
											}
										})
										obj['property'] = val2.property
										obj['blockName'] = val2.blockName
										obj['id'] = index2
										obj['blockid'] = index
										obj['data'] = JSON.parse(JSON.stringify(style))
										listtemp.push(JSON.parse(JSON.stringify(obj)))
									})
									datalist.push(listtemp)
								})
								that.halfdatalist = datalist
								that.iscontentdetail1 = true
								console.log(that.halfdatalist)
							},
						})
					},
				})
			},
			
			closemask(){
				this.iscontentdetail1 = false
			},
			
			naviback(){
				var that = this
				var item = that.item 
				var dataitem = that.dataitem
				item.forEach((val)=>{
					val.data.forEach((val2)=>{
						if(val2.name == that.ColNameQty){
							val2.style.colValue = dataitem[that.ColNameQty]
						}
					})
				})
				let pages = getCurrentPages();
				let beforePage = pages[pages.length  -2];
				beforePage.$vm.reload(JSON.stringify(item),JSON.stringify(that.skuselected),that.colNameWriteBackBasedOn)
				uni.navigateBack({delta: 1})
			},
			
			changecheck(type,e){
				var that = this
				if(type == 'head'){
					var datahead = that.datahead
					datahead.forEach((val)=>{
						val.checked = false
					})
					var result = e.detail.value
					if(JSON.stringify(result)!='[]'){
						result.forEach((val)=>{
							datahead.forEach((val2)=>{
								if(val == val2[that.specValue1]){
									val2.checked = true
								}
							})
						})
					}
					that.datahead = datahead
				}
				if(type == 'head2'){
					var datahead = that.datahead2
					datahead.forEach((val)=>{
						val.checked = false
					})
					var result = e.detail.value
					if(JSON.stringify(result)!='[]'){
						result.forEach((val)=>{
							datahead.forEach((val2)=>{
								if(val == val2[that.specValue2]){
									val2.checked = true
								}
							})
						})
					}
					that.datahead2 = datahead
				}
				var datadetail = that.datadetail
				var specValue = that.specValue1
				var specValue2 = that.specValue2
				var datahead = that.datahead
				var datahead2 = that.datahead2
				datadetail.forEach((val)=>{
					var valt = val[specValue]
					var valt2 = val[specValue2]
					var visible = false
					datahead.forEach((val2)=>{
						if(val2.checked && val2[specValue]==valt){
							datahead2.forEach((val3)=>{
								if(val3.checked && val3[specValue2]==valt2){
									visible = true
								}
							})
						}
					})
					val.visible = visible
				})
				that.datadetail = datadetail
			},
		
		}
		
	}
</script>

<style>
</style>